package com.jams.goodox.activity.mine.bill;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.jams.goodox.utils.DayUtils;

public class BirthdayDateTimePickerDialog2 extends AlertDialog implements OnClickListener {
	private BirthdayDateTimePicker2 mDateTimePicker;
	private OnBirthDateTimeSetListener mOnDateTimeSetListener;
	int year;
	int month;
	int day;

	public BirthdayDateTimePickerDialog2(Context context, int year, int month, int day) {
		super(context);
		if (year > 0) {
			DayUtils.setYear = year;
		}
		if (month > 0) {
			DayUtils.setMonth = month;
		}
		if (day > 0) {
			DayUtils.setDay = day;
		}
		mDateTimePicker = new BirthdayDateTimePicker2(context, 0, DayUtils.setYear, DayUtils.setMonth, DayUtils.setDay);
		setView(mDateTimePicker);
		/*
		 * 实现接口，实现里面的方法
		 */
		mDateTimePicker.setOnYearChangedListener(new BirthdayDateTimePicker2.OnYearChangedListener() {
			@Override
			public void onDateTimeChanged(BirthdayDateTimePicker2 view, int year, int month, int day) {
				setDate(year, month, day);
			}
		});

		setButton("确定", this);
		setButton2("取消", (OnClickListener) null);
		setTitle("出生日期");
		setDate(DayUtils.setYear, DayUtils.setMonth, DayUtils.setDay);
	}

	//
	public BirthdayDateTimePickerDialog2(Context context, int years, int months) {
		super(context);
		mDateTimePicker = new BirthdayDateTimePicker2(context, 1, years, months, 0);
		setView(mDateTimePicker);
		/*
		 * 实现接口，实现里面的方法
		 */
		mDateTimePicker.setOnYearChangedListener(new BirthdayDateTimePicker2.OnYearChangedListener() {
			@Override
			public void onDateTimeChanged(BirthdayDateTimePicker2 view, int year, int month, int day) {
				setDate1(year, month, day);
			}
		});
		
		setButton("确定", this);
		setButton2("取消", (OnClickListener) null);
		setTitle("请选择");
		setDate1(years, months, 0);
	}
	
	private void setDate1(int year, int month, int day) {
		this.month = month;
		this.day = day;
		this.year = year;
		
	}
	
	private void setDate(int year, int month, int day) {
		this.month = month;
		this.day = day;
		this.year = year;
		setTitle("出生日期: " + DayUtils.getBirthdayEntime(year, month, day));
		
	}
	
	/*
	 * 接口回調控件 秒数z
	 */
	public interface OnBirthDateTimeSetListener {
		void OnDateTimeSet(AlertDialog dialog, int year, int month, int day);
	}
	
	/*
	 * 对外公开方法让Activity实现
	 */
	public void setOnDateTimeSetListener(OnBirthDateTimeSetListener callBack) {
		mOnDateTimeSetListener = callBack;
	}
	
	public void onClick(DialogInterface arg0, int arg1) {
		if (mOnDateTimeSetListener != null) {
			mOnDateTimeSetListener.OnDateTimeSet(this, year, month, day);
		}
	}
}
